/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.brainstretch.ejb.managers;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author mrodaitis
 */
public class EJBUtils {
    public static String hashString(String toHash){
        String result = "";
        try {
            byte[] hashed = MessageDigest.getInstance("SHA-256").digest(toHash.getBytes());
            for(int i = 0; i<hashed.length; i++){
                String hexByte = Integer.toHexString(0xff & hashed[i]);
                if(hexByte.length()==1){
                    hexByte = "0"+hexByte;
                }
                result += hexByte;
            }
        } catch (NoSuchAlgorithmException ex) {
            
        }
        return result;
    }
}
